home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1998-03-19 | 24.8 KB | 637 lines | [ TEXT/MPS ]
# # **************************************************************************** # # File Name: Palette.Lib # # Contains: xxx put contents here xxx # # Written by: KTA, KL, ML, GS et al # # Copyright: © 1993-1996 by Apple Computer, Inc., all rights reserved. # # **************************************************************************** # C h a n g e H i s t o r y (most recent first): # **************************************************************************** # # Vers Date Author Description # ---- -------- ------ --------------------------------------------- # 1.0.113> 2/8/96 JC Changed all window .r (Rect) traits to .b (bound) traits and # changed any window insets to reflect new bound rect. # 1.0.112> 12/19/95 ML add global hook to SelFromMenuItemPopUp and SelFromPopUp # .0.111+> 12/19/95 ML add global hook to # 1.0.111> 12/18/95 ML SelFromMenuItemPopUp - Move to left first, then top of palette # to maintain selection # .0.110+> 12/18/95 ML # 1.0.110> 12/8/95 ML CalcOffset - revise for single row of tools # 1.0.19+> 12/8/95 ML # <1.0.19> 12/6/95 ML CalcOffset - card theRect s/b <4 # 1.0.18+> 12/6/95 ML CalcOffset - card theRect s/b <4 # <1.0.18> 11/13/95 ML CalcOffset - add support for left margin in kPalWind # 1.0.17+> 11/13/95 ML CalcOffset - add support for left margin in kPalWind # <1.0.17> 11/10/95 ML Tool Structure accessors - added support for gradient, # background color, text color, and pen patterns # 1.0.16+> 11/9/95 ML support for more palettes # <1.0.16> 11/9/95 ML SelFromMenuItemPopUp, SelFromPopUp - removed mismatched else # 1.0.15+> 11/9/95 ML Mismatched else # <1.0.15> 12/12/94 ML removed gTargetcheck # 1.0.14+> 12/12/94 ML removed gTargetcheck # <1.0.14> 11/29/94 ML Added Support for exception handling # 1.0.13+> 11/29/94 ML Added Support for exception handling # <1.0.13> 9/19/94 KTA SelFromPopUp(), SelFromMenuItemPopUp() - Turn gTargetCheck off # so won't match the target when mouseDown. # <1.0.12> 9/19/94 KTA CalcOffset() - Added a rewrite by Michael Press plus a fix when # a single column of tools for kPalDocWind,kPalWind. # <1.0.11> 5/2/94 KTA Removed all references to kPullOffPal, kScrollPal. # <1.0.10> 3/17/94 KTA Added support for kMenuItemPopUpPal palettes. # <1.0.9> 3/16/94 KTA New TCS set - kTCSetSelectFromPalette. # <1.0.8> 3/16/94 KTA Moved TCS calls to selection routines. # <1.0.7> 11/19/93 NAGA modify TCS format # <1.0.6> 8/25/93 KTA Added support for parity checking the TCS stack. # <1.0.5> 8/3/93 KTA SelFromCoord() - There was no returnVal for absolute coordinate # moves. # <1.0.4> 6/8/93 NAGA unmark tasks that are not published # <1.0.3> 5/21/93 NAGA Adding header and porting old files to follow new standards # # **************************************************************************** # ######################################################################## # External libraries #======================================================================= Libraries "TCS.Lib","Output.Lib","UserInterface.Lib", "ExceptionHandling.lib"; ######################################################################### ######################################################################### # Palette Structure Accessors() #======================================================================== # Author: DM # Description: These functions access the data in an palette data struct # Parameters: palStruct # Returns: the requested data element or list #======================================================================== # History: # ######################################################################### task GetPalRect(palStruct) begin return( palStruct[1] ); end; task GetPalType(palStruct) begin return( palStruct[2] ); end; task GetPalMatrixSize(palStruct) begin return( palStruct[3] ); end; task GetPalOffsets(palStruct) begin return( palStruct[4] ); end; #task GetPalHeaderSize(palStruct) begin return( palStruct[5] ); end; # Not used #task GetPalOnDesk(palStruct) begin return( palStruct[6] ); end; # Not used task InsertPalRect(rect, pS) begin return( replace(rect, 1, pS )); end; task InsertPalOnDesk(onDesk, pS) begin return( replace(onDesk, 6, pS ));end; ######################################################################### # Tool Structure Accessors() #======================================================================== # Author: DM # Description: These functions access the data in an tool data struct # Parameters: elemStruct # Returns: the requested data element or list #======================================================================== # History: # ML 11/10/95 Added support for gradients, background colors, text colors, # and pen patterns ######################################################################### ## elemStruct is the data structure that completely specifies tools ## elemStruct { ## ElemNum ## PalNum ## ElemName ## ElemType - kClick := move-click ## (Pointlist is single set of points) ## - kDrag := move-pressmouse-move-releasMouse ## (Pointlist is two set of points) ## == Pointlist is defined by Global gNumPoints == ## - kMultiDrag := move-pressmouse-move-move…releasMouse ## - kMultiClick:= move-click-move-click-move… ## - kMultiClickDragTool := move-pressmouse-move-releasMouse-pressmouse-move-releasMouse… ## ## elemDblClk - Flag to doulble click when finished ## - 0 := No DoubleClick ## - 1 := DoubleClick ## ## SetAttribute - Flag indicating when to set attributes ## - 0 := No attributes to set ## - 1 := Set attribute before drawing object ## - 2 := Set attribute after drawing object ## - "str" := Type <'Str'> after drawing object (texttool) ## } ## Defined ElemTypes: ## ######################################################################### ## Example: global CharTool := { ElemNum, PalNum,"ElemName", ElemType, elemDblClk}; ## global CharTool := { 17 , 1 ,"Char" , kClick , 0 }; ######################################################################### task GetElemNum(elemStruct) begin return( elemStruct[1] ); end; task GetPalNum(elemStruct) begin return( elemStruct[2] ); end; task GetElemName(elemStruct) begin return( elemStruct[3] ); end; task GetElemType(elemStruct) begin return( elemStruct[4] ); end; task GetElemDblClk(elemStruct) begin return( elemStruct[5] ); end; task GetAttributes(elemStruct) begin return( elemStruct[6] ); end; task GetSetAttribute(elemStruct) begin return( elemStruct[6][1] ); end; task GetPatternFlag(elemStruct) begin return( elemStruct[6][2] ); end; task GetLineFlag(elemStruct) begin return( elemStruct[6][3] ); end; task GetColorFlag(elemStruct) begin return( elemStruct[6][4] ); end; task GetGradientFlag(elemStruct) begin return( elemStruct[6][5] ); end; task GetBackgroundColorFlag(elemStruct) begin return( elemStruct[6][6] ); end; task GetTextColorFlag(elemStruct) begin return( elemStruct[6][7] ); end; task GetPenPatternFlag(elemStruct) begin return( elemStruct[6][8] ); end; task InsertElemNum(eNum, tS) begin return( replace( eNum, 1, tS )); end; task InsertPalNum(pNum, tS) begin return( replace( pNum, 2, tS )); end; task InsertElemName(eNam, tS) begin return( replace( eNam, 3, tS )); end; task InsertElemType(eTyp, tS) begin return( replace( eTyp, 4, tS )); end; task InsertElemDblClk(eDbc, tS) begin return( replace( eDbc, 5, tS )); end; task InsertSetAttribute(eDbc, tS) begin return( replace( eDbc, 6, tS )); end; ######################################################################### # PalettePicker(elemStruct) #======================================================================== # Author: DM # Description: Dispatches selection request to palette handlers. # Parameters: elemStruct:= Structure containing element info # Only the first 3 elements are required. # kInWindPal := 1; # kIsWindPal := 2; # kPopUpPal := 4; # # Return Values: 1 - OK # 0 - error # Examples: PalettePicker(elemStruct); #======================================================================== # History: # KTA 8/24/93 TCS stack parity check # KTA 3/16/94 Moved TCS calls to tool selection routines. ######################################################################### TASK PalettePicker(elemStruct := {}, ObjectNumber := 0) begin if (global gDebugFlag) Println "----- PalettePicker() - Palette.lib --------"; global kPalDocWind, kPalWind, kPopUpPal, kMenuItemPopUpPal,gPaletteList; thePalNum := GetPalNum(elemStruct); # get the palette number thePalette := gPaletteList[thePalNum]; # get the palette thePalType := GetPalType(thePalette); # get the palette type if (TypeOF(thePalNum) = 'list') #### Direct Coordinate Tools begin returnVal := SelFromCoord(elemStruct,ObjectNumber); # no palette only coordinates if (returnVal) returnVal := elemStruct; end; else if (thePalType = kPalDocWind) ##### Palette in a Document Window returnVal := SelFromDocWind(elemStruct, ObjectNumber); else if (thePalType = kPalWind) ##### Palette within a seperate window returnVal := SelFromPalWind(elemStruct, ObjectNumber); else if (thePalType = kPopUpPal) ##### Popup Palette returnVal := SelFromPopUp(elemStruct, ObjectNumber); else if (thePalType = kMenuItemPopUpPal) ##### MenuItemPopUp Palette returnVal := SelFromMenuItemPopUp(elemStruct, ObjectNumber); else begin LogStr("No selection function declared for palette type {thePalType}",2); returnVal := 0; end; return(returnVal); #Return what sub routines return end; ######################################################################### # CalcOffset(elemStruct) #======================================================================== # Author: KTA # Description: Calculates tool offsets based on palette info. # Parameters: elemStruct:= structure containing element info # Return Values: toolOffset:= {x,y} # 0 - error # Examples: CalcOffset(elemStruct); #======================================================================== # History: # KTA 9/19/94 Added a rewrite by Michael Press plus a fix when a single column # of tools for kPalDocWind,kPalWind. # ML 11/13/95 add left margin support for kPalWind # ML 12/6/95 Card(theRect) < 3 should be 4 # ML 12/8/95 revise for single row of tools # JC 2/6/96 Changed TheWindow.r to TheWindow.b. ######################################################################### task CalcOffset(elemStruct) begin global gPaletteList, kPopUpPal, kMenuItemPopUpPal, kPalDocWind, kPalWind; #LogStr("Calculating tool offset"); thePalNum := GetPalNum(elemStruct); thePalette := gPaletteList[thePalNum]; thePalType := GetPalType(thePalette); elemNum := GetElemNum(elemStruct); theRect := GetPalRect(thePalette); theOffsets := GetPalOffsets(thePalette); theMatrix := GetPalMatrixSize(thePalette); headerHeight := 0; leftMargin := 0; xOffset := theOffsets[1]; yOffset := theOffsets[2]; elemsAcross := theMatrix[1]; elemsDown := theMatrix[2]; if ((Card(theRect) < 4)) # kPalWind begin # be a seperate palette window if (theRect[2]) headerHeight := theRect[2]; if (theRect[3]) leftMargin := theRect[3]; theWindow := Findwindow(theRect[1]); if (TheWindow) theRect := TheWindow.b; end; elemTemp := elemNum-1; qTemp := elemTemp / elemsAcross; rTemp := ( elemTemp ) mod elemsAcross; xMove := rtemp * xOffset; yMove := qtemp * yOffset; xAbsoluteOffSet := theRect[1] + leftMargin; yAbsoluteOffSet := theRect[2] + headerHeight; if (thePalType = kPopUpPal) or (thePalType = kMenuItemPopUpPal) #To handle popup palettes when selecting from a begin # palette you begin at the correct location. xAbsoluteOffSet := 0; yAbsoluteOffSet := 0; end; if (elemsAcross = 1) begin xAbsoluteOffSet := 0; if (xOffset = 0) and ((thePalType = kPalDocWind) or (thePalType = kPalWind)) xOffset := theRect[1] + theRect[3]; end; if (elemsDown = 1) begin yAbsoluteOffSet := 0; if (yOffset = 0) and ((thePalType = kPalDocWind) or (thePalType = kPalWind)) yOffset := theRect[2] + theRect[4]; end; xMove := xMove + xAbsoluteOffSet + xOffset/2; yMove := yMove + yAbsoluteOffSet + yOffset/2; If((xMove) or (yMove)) returnVal := {xMove, yMove}; else returnVal := 0; #Println "This is the CalcOffset returnVal - ", returnVal; return(returnVal); end; # CalcOffset() ######################################################################### # SelFromDocWind(elemStruct) #======================================================================== # Author: DM # Description: Selects tools from palettes that are builtin to doc windows. # You can also specify a Rect in Global coordinates outside # the document window. # Parameters: elemStruct # pObjectNumber - Number to identify the elements required for # to draw the object. # Return Values: 1 - OK # 0 - error # Examples: SelFromDocWind(elemStruct); #======================================================================== # History: # KTA 3/15/94 Added TCS support ######################################################################### TASK SelFromDocWind(elemStruct, pObjectNumber) begin global gPaletteList; windSpecifier := 0; thePalNum := GetPalNum(elemStruct); thePalette := gPaletteList[thePalNum]; theRect := GetPalRect(thePalette); theElemNum := GetElemNum(elemStruct); # get the elem number theElemName := GetElemName(elemStruct); # get the elem name theToolDescriptor := "PaletteNumber : {thePalNum} / ToolNumber : {theElemNum} / ToolName : {theElemName}"; LogStr("Preparing to select the '{theElemName}' tool / number - '{theElemNum}' from Palette '#{thePalNum}' which is contained within a document window",4); TCSStart({ 1, global kTCSetSelectFromPalette },"Select from a Palette in document window"); # Start TCS whereMove := CalcOffset(elemStruct); if(whereMove) begin xMove := whereMove[1]; yMove := whereMove[2]; temp := global gDisableAllLogging; if not(global gDebugFlag) gDisableAllLogging := 1; if (Card(theRect) = 4) MoveMouse(xMove, yMove, 1, 2); # Select Tool/Absolute Coordinates else if(Card(theRect) = 5) begin windSpecifier := theRect[5]; MoveRelativeToWindow(xMove, yMove, windSpecifier, 2); # Select Tool/Relative to doc window end; gDisableAllLogging := temp; returnVal := 1; end; else returnVal := 0; TCSEnd({ 1, global kTCSetSelectFromPalette }, returnVal,,pObjectNumber,theToolDescriptor); return(returnVal); end; ######################################################################### # SelFromPalWind(elemStruct) #======================================================================== # Author: DM # Description: Selects tools from palettes that are windows. # Parameters: elemStruct:= structure containing element info # pObjectNumber - Number to identify the elements required for # to draw object. # Return Values: 1 - OK # 0 - error # Examples: SelFromPalWind(elemStruct); #======================================================================== # History: # KTA 3/15/94 Added TCS support ######################################################################### TASK SelFromPalWind(elemStruct, pObjectNumber) begin returnVal := 0; thePalNum := GetPalNum(elemStruct); # get the palette number theElemName := GetElemName(elemStruct); # get the elem name theElemNum := GetElemNum(elemStruct); # get the elem number theToolDescriptor := "PaletteNumber : {thePalNum} / ToolNumber : {theElemNum} / ToolName : {theElemName}"; LogStr("Preparing to select the '{theElemName}' tool / number - '{theElemNum}' from Palette '#{thePalNum}' which is a separate window",4); TCSStart({ 2, global kTCSetSelectFromPalette },"Select from a Palette Window"); # Start TCS whereMove := CalcOffset(elemStruct); if(whereMove) begin xMove := whereMove[1]; yMove := whereMove[2]; temp := global gDisableAllLogging; if not(global gDebugFlag) gDisableAllLogging := 1; MoveMouse(xMove, yMove, , 2); # Select tool gDisableAllLogging := temp; returnVal := 1; end; else returnVal := 0; TCSEnd({ 2, global kTCSetSelectFromPalette }, returnVal,,pObjectNumber,theToolDescriptor); return(returnVal); end; ######################################################################### # SelFromCoord(elemStruct, ObjectNumber) #======================================================================== # Author: KTA # Description: Selects tools from coodinates either global or relative to the # front window. # Parameters: elemStruct:= structure containing tool info # Return Values: Returns what is returned by MoveRelativeToWindow() or MoveMouse() # Examples: SelFromCoord(elemStruct); #======================================================================== # History: # KTA 8/3/93 There was no returnVal for absolute coordinate moves. # KTA 8/24/93 TCS stack parity check ######################################################################### TASK SelFromCoord(elemStruct,ObjectNumber) begin temp := global gDisableAllLogging; if not(global gDebugFlag) gDisableAllLogging := 1; theElemName := GetElemName(elemStruct); # get the elem name theCoord := GetPalNum(elemStruct); # get the palette number theElemNum := GetElemNum(elemStruct); # get the elem number xCoor := theCoord[1]; yCoor := theCoord[2]; RelativeFlag := theCoord[3]; theToolDescriptor := "ToolCoords : {theCoord} / ToolNumber : {theElemNum} / ToolName : {theElemName}"; TCSStart({ 4, global kTCSetSelectFromPalette },"Select from Coordinates"); # Start TCS Str := "Selecting the '{theElemName}' tool from coordinates ∂({xCoor},{yCoor}∂)"; if (RelativeFlag) # RelativeToWindow begin returnVal := MoveRelativeToWindow(xCoor, yCoor, ,2,,RelativeFlag); str1:= " which are relative to the front window"; end; else # Absolute Coordinates begin MoveMouse(xCoor, yCoor, , 2); returnVal:= 1; str1:= " which are absolute coordinates"; end; # Tool has been Selected Str := Str + str1; gDisableAllLogging := temp; LogStr(Str); if (returnVal) TCSReturn :=1; else TCSReturn :=0; TCSEnd({ 4, global kTCSetSelectFromPalette }, TCSReturn,,ObjectNumber,theToolDescriptor); return(returnVal); end; ######################################################################### # SelFromPopUp(elemStruct, pObjectNumber) #======================================================================== # Author: DM # Description: Selects tools from palettes that pop up. # Parameters: elemStruct:= structure containing element info # pObjectNumber - Number to identify the elements required for # to draw the object. # Return Values: 1 - OK # 0 - error # Examples: SelFromPopUp(elemStruct); #======================================================================== # History: # KTA 3/15/94 Added TCS support # KTA 9/19/94 Turn gTargetCheck off so won't match the target when mouseDown. # ML 11/29/94 Added exception handling support # ML 12/12/94 Removed gTargetcheck # ML 11/9/95 Removed mismatched else after global gDebugFlag # ML 12/19/95 add global hook ######################################################################### TASK SelFromPopUp(elemStruct, pObjectNumber) begin global gPaletteList, gAppVerify; thePalNum := GetPalNum(elemStruct); thePalette := gPaletteList[thePalNum]; theRect := GetPalRect(thePalette); theElemNum := GetElemNum(elemStruct); # get the elem number theElemName := GetElemName(elemStruct); # get the elem name theToolDescriptor := "PaletteNumber : {thePalNum} / ToolNumber : {theElemNum} / ToolName : {theElemName}"; LogStr("Preparing to select the '{theElemName}' tool / number - '{theElemNum}' from Palette '#{thePalNum}' which is a popup palette",4); TCSStart({ 3, global kTCSetSelectFromPalette },"Select from a PopUp Palette"); # Start TCS if (global gDebugFlag) println "This is the ElemStruct", elemStruct; # if we are moving with absolute coordinates the rect should have 4 items if (Card(theRect) = 5) # IF windSpecifier := theRect[5]; whereMove := CalcOffset(elemStruct); if(whereMove) begin xMove := whereMove[1]; yMove := whereMove[2]; returnVal := 1; end; else returnVal := 0; tempSpeed := MouseSpeed(5); temp := global gDisableAllLogging; if not(global gDebugFlag) gDisableAllLogging := 1; if (isUndefined(windSpecifier)) MoveMouse(theRect[1], theRect[2], 1, 0); # move to pop-point else MoveRelativeToWindow(theRect[1], theRect[2], windSpecifier, 0); # move to pop-point tempAppVerify := gAppVerify; gAppVerify := 0; _PressMouse(); wait(2); MoveMouse(theRect[3] - theRect[1], theRect[4] - theRect[2], 0, 0); # press mouse - move to topLeft item MoveMouse(xMove, yMove, 0, 0); # move to item and release if (global gSelFromPopUpHook) call (gSelFromPopUpHook, elemStruct, pObjectNumber); _ReleaseMouse(); gAppVerify := tempAppVerify; gDisableAllLogging := temp; MouseSpeed(tempSpeed); TCSEnd({ 3, global kTCSetSelectFromPalette }, returnVal,,pObjectNumber,theToolDescriptor); return(returnVal); end; ######################################################################### # SelFromMenuItemPopUp(elemStruct) #======================================================================== # Author: KTA # Description: Selects tools from palettes that pop up when selecting a # menuItem. # Parameters: elemStruct:= structure containing element info # pObjectNumber - Number to identify the elements required for # to draw the object. # Return Values: 1 - OK # 0 - error # Examples: SelFromMenuItemPopUp(elemStruct); #======================================================================== # History: # KTA 3/15/94 Added TCS support # KTA 9/19/94 Turn gTargetCheck off so won't match the target when mouseDown. # ML 11/29/94 Added exception handling support # ML 12/12/94 Removed gTargetcheck # ML 11/9/95 Removed mismatched else after global gDebugFlag # ML 12/18/95 Move to left first, then top of palette for maintain selection # ML 12/19/95 add global hook ######################################################################### TASK SelFromMenuItemPopUp(elemStruct, pObjectNumber) begin global gPaletteList, gAppVerify; thePalNum := GetPalNum(elemStruct); thePalette := gPaletteList[thePalNum]; theRect := GetPalRect(thePalette); theElemNum := GetElemNum(elemStruct); # get the elem number theElemName := GetElemName(elemStruct); # get the elem name theToolDescriptor := "PaletteNumber : {thePalNum} / ToolNumber : {theElemNum} / ToolName : {theElemName}"; LogStr("Preparing to select the '{theElemName}' tool / number - '{theElemNum}' from Palette '#{thePalNum}' which is a menuItem popup palette",4); TCSStart({ 5, global kTCSetSelectFromPalette },"Select from a MenuItemPopUp Palette"); # Start TCS if (global gDebugFlag) println "This is the ElemStruct", elemStruct; # if we are moving with absolute coordinates the rect should have 6 items if (Card(theRect) = 7) # IF windSpecifier := theRect[7]; whereMove := CalcOffset(elemStruct); if(whereMove) begin xMove := whereMove[1]; yMove := whereMove[2]; returnVal := 1; end; else returnVal := 0; tempSpeed := MouseSpeed(5); temp := global gDisableAllLogging; if not(global gDebugFlag) gDisableAllLogging := 1; if (isUndefined(windSpecifier)) begin MoveMouse(theRect[1], theRect[2], 1, 0); # move to pop-point MoveMouse(theRect[3], theRect[4], 1, 3); # move to menuItem pop-point end; else begin MoveRelativeToWindow(theRect[1], theRect[2], windSpecifier, 0); # move to pop-point MoveRelativeToWindow(theRect[3], theRect[4], windSpecifier, 3); # move to menuItem pop-point end; tempAppVerify := gAppVerify; gAppVerify := 0; _PressMouse(); wait(2); MoveMouse(theRect[5] - theRect[3], 0, 0, 0); # press mouse - move to Left item MoveMouse(0, theRect[6] - theRect[4], 0, 0); # press mouse - move to top item MoveMouse(xMove, yMove, 0, 0); # move to item and release if (global gSelFromMenuItemPopUpHook) call (gSelFromMenuItemPopUpHook, elemStruct, pObjectNumber); _ReleaseMouse(); gAppVerify := tempAppVerify; gDisableAllLogging := temp; MouseSpeed(tempSpeed); TCSEnd({ 5, global kTCSetSelectFromPalette }, returnVal,,pObjectNumber,theToolDescriptor); return(returnVal); end; ######################################################################### # GetRandomElement() #======================================================================== # Author: DM # Description: # Parameters: palStruct # Returns: #======================================================================== # History: # ######################################################################### TASK GetRandomElement(palStruct) begin if (global gDebugFlag) Println "----- GetRandomElement() - Palette.lib --------"; theMatrix := GetPalMatrixSize(palStruct); numCells := theMatrix[1]*theMatrix[2]; elemNum := random(1, numCells); return elemNum; end; # GetRandomElement()